package com.reform.controller.teacher;


import com.reform.res.Result;
import com.reform.service.ITeacherService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * <p>
 * 教师表 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-06-26
 */
@Api(tags = "TeacherController")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    ITeacherService teacherService;

    /**
     * 获取当前用户信息-school
     */
    @ApiOperation(value = "获取当前用户全部信息",notes = "获取当前用户全部信息")
    @GetMapping("/getDefaultTeacherInfo")
    public Result getDefaultTeacherInfo(HttpServletRequest request) throws SQLException {
        return teacherService.getDefaultTeacherInfo(request);
    }

    /**
     * 获取当前用户信息-local
     */
    @ApiOperation(value = "获取当前用户信息-本地库",notes = "获取当前用户信息-本地库")
    @GetMapping("/getDefaultLocalTeacherInfo")
    public Result getDefaultLocalTeacherInfo(HttpServletRequest request){
        return teacherService.getDefaultLocalTeacherInfo(request);
    }

    @ApiOperation(value = "修改用户邮箱",notes = "修改用户邮箱")
    @PostMapping("/changeEmail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "password",value = "密码",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "code",value = "验证码",paramType = "query",dataTypeClass = String.class,required = true),
    })
    public Result changeEmail(String email,String password,String code,HttpServletRequest request){
        return teacherService.changeEmail(email,password,code,request);
    }

    @ApiOperation(value = "修改用户密码",notes = "修改用户密码")
    @PostMapping("/changePassword")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "password",value = "密码",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "newPassword",value = "新密码",paramType = "query",dataTypeClass = String.class,required = true),
    })
    public Result changePassword(String password,String newPassword, HttpServletRequest request){
        System.out.println(password + "-----" + password.length());
        System.out.println(newPassword + "-----" + newPassword.length());
        System.out.println(request.getHeader("token"));
        return teacherService.changePassword(password,newPassword,request);
    }

    @ApiOperation(value = "忘记密码找回",notes = "忘记密码找回")
    @PostMapping("/findPwd")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gh",value = "工号",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "password",value = "密码",paramType = "query",dataTypeClass = String.class,required = true),
    })
    public Result findPassword(String gh,String email,String password){
        return teacherService.findPassword(gh,email,password);
    }

    @ApiOperation(value = "重置教师账号",notes = "重置教师账号")
    @PostMapping("/resetTeacher")
    @ApiImplicitParam(name = "gh",value = "工号",paramType = "query",dataTypeClass = String.class,required = true)
    public Result resetTeacher(String gh){
        return teacherService.resetTeacher(gh);
    }

    @ApiOperation(value = "获取全校教师数据",notes = "获取全校教师数据")
    @GetMapping("/getAllTeacherInfo")
    public Result getAllTeacherInfo() throws SQLException {
        return teacherService.getAllTeacherInfo();
    }

    @ApiOperation(value = "根据教师工号获取身份信息",notes = "根据教师工号获取身份信息")
    @PostMapping("/getTeacherTypeByGH")
    @ApiImplicitParam(name = "gh",value = "工号",paramType = "query",dataTypeClass = String.class,required = true)
    public Result getTeacherTypeByGH(String gh) throws SQLException {
        return teacherService.getTeacherTypeByGH(gh);
    }

    @ApiOperation(value = "获取教师待办事项",notes = "获取教师待办事项")
    @GetMapping("/getTeacherDealt")
    public Result getTeacherDealt(HttpServletRequest request) throws SQLException {
        return teacherService.getTeacherDealt(request);
    }

}
